package kr.pe.johnkim.pushchat.mobile.dao;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatFriend;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 6. 26.
 */
@Repository
public class PushChatFriendDaoImpl extends SqlSessionDaoSupport implements PushChatFriendDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatFriendDaoImpl.class);

    /**
     * 친구 중복 확인을 한다.
     *
     * @param pushChatFriend
     * @return
     */
    @Override
    public PushChatFriend selectDuplicationFriend(PushChatFriend pushChatFriend) {
        logger.info("selectDuplicationFriend");
        return (PushChatFriend)this.getSqlSession().selectOne("PUSHCHAT_FRIEND.selectDuplicationFriend", pushChatFriend);
    }

    /**
     * 친구를 등록 한다.
     *
     * @param pushChatFriend
     */
    @Override
    public void registerFriend(PushChatFriend pushChatFriend) {
        logger.info("registerFriend");
        this.getSqlSession().insert("PUSHCHAT_FRIEND.registerFriend", pushChatFriend);
    }

    /**
     * 친구를 비활성화 한다.
     *
     * @param pushChatFriend
     */
    @Override
    public void updateDeactivateFriend(PushChatFriend pushChatFriend) {
        logger.info("updateDeactivateFriend");
        this.getSqlSession().update("PUSHCHAT_FRIEND.updateDeactivateFriend", pushChatFriend);
    }

    /**
     * 친구 목록을 가져 온다.
     *
     * @param pushChatFriend
     * @return
     */
    @Override
    public List<PushChatFriend> selectFriendList(PushChatFriend pushChatFriend) {
        logger.info("selectFriendList");
        return this.getSqlSession().selectList("PUSHCHAT_FRIEND.selectFriendList", pushChatFriend);
    }
}
